﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Peking_Duck
{
    public partial class NPCGenerator : Form
    {
        public NPCGenerator()
        {
            InitializeComponent();
        }

        private void lblModel1_Click(object sender, EventArgs e)
        {

        }

        private void lblRank_MouseHover(object sender, EventArgs e)
        {
            tooltipRank.Show("The rank of the creature: 0 = Normal, 1 = Elite, 2 = Rare Elite, 3 = World Boss, 4 = Rare.", lblRank);
        }

        private void lblEntry_Click(object sender, EventArgs e)
        {

        }

        private void lblEntry_MouseHover(object sender, EventArgs e)
        {
            tooltipRank.Show("Creature's unique id.", lblEntry);
        }

        private void NPCGenerator_Load(object sender, EventArgs e)
        {
            comboboxClass.SelectedIndex = 1;
        }

        private void btnGen_Click(object sender, EventArgs e)
        {


            if
            (
                textboxEntry.Text == "" ||
                textboxDiff1.Text == "" ||
                textboxDiff2.Text == "" ||
                textboxDiff3.Text == "" ||
                textboxKill1.Text == "" ||
                textboxKill2.Text == "" ||
                textboxModel1.Text == "" ||
                textboxModel2.Text == "" ||
                textboxModel3.Text == "" ||
                textboxModel4.Text == "" ||
                textboxName.Text == "" ||
                textboxFactionA.Text == "" ||
                textboxFactionH.Text == "" ||
                textboxScale.Text == "" ||
                textboxFlags.Text == "" ||
                textboxUnitFlags.Text == "" ||
                textboxDynamicFlags.Text == "" ||
                textboxMinLevel.Text == "" ||
                textboxMaxLevel.Text == "" 
            )
            {
                MessageBox.Show("Error! One of the required input fields is set to null. \nThis is unacceptable. Use 0 instead of blank", "Error in Data fields!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                try
                {
                    QueryHandler Handler = new QueryHandler();
                    uint _uiRankNum = Decimal.ToUInt32(numupdownRank.Value);
                    uint _uiClassID = 0;
                    bool _bDoParse = false;
                    switch (comboboxClass.SelectedItem.ToString())
                    {
                        case "WARRIOR":
                            _uiClassID = 1;
                            _bDoParse = true;
                            break;
                        case "PALADIN":
                            _uiClassID = 2;
                            _bDoParse = true;
                            break;
                        case "ROGUE":
                            _uiClassID = 4;
                            _bDoParse = true;
                            break;
                        case "MAGE":
                            _uiClassID = 8;
                            _bDoParse = true;
                            break;
                        default:
                            MessageBox.Show("Error! You have specified an invalid class. Please try again.", "Error in Data fields!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            break;
                    }
                    if (_bDoParse == true)
                    {
                        Handler.GenerateCreature(
                                      uint.Parse(textboxEntry.Text),
                                      uint.Parse(textboxDiff1.Text),
                                      uint.Parse(textboxDiff2.Text),
                                      uint.Parse(textboxDiff3.Text),
                                      uint.Parse(textboxKill1.Text),
                                      uint.Parse(textboxKill2.Text),
                                      uint.Parse(textboxModel1.Text),
                                      uint.Parse(textboxModel2.Text),
                                      uint.Parse(textboxModel3.Text),
                                      uint.Parse(textboxModel4.Text),
                                      textboxName.Text,
                                      textboxSubName.Text,
                                      uint.Parse(textboxFactionA.Text),
                                      uint.Parse(textboxFactionH.Text),
                                      _uiRankNum,
                                      uint.Parse(textboxScale.Text),
                                      uint.Parse(textboxFlags.Text),
                                      _uiClassID,
                                      uint.Parse(textboxMinLevel.Text),
                                      uint.Parse(textboxMaxLevel.Text),
                                      uint.Parse(textboxUnitFlags.Text),
                                      uint.Parse(textboxDynamicFlags.Text)
                                      );
                    }
                }
           
                catch (FormatException)
                {
                    MessageBox.Show("Error! One of the required integer input fields is set to a non-numeric value. \nThis is unacceptable. Only 0-9 is allowed", "Error in Data fields!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (Exception err)
                {

                    MessageBox.Show("Error! This occurred\n" + err + "\n - Sorry!");
                }
            }


        }

        private void numupdownRank_ValueChanged(object sender, EventArgs e)
        {

        }

        private void textboxFlags_TextChanged(object sender, EventArgs e)
        {

        }

        private void comboboxClass_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void lblDynamicFlags_Click(object sender, EventArgs e)
        {

        }

        private void NPCGenerator_Deactivate(object sender, EventArgs e)
        {
        }
    }
}
